#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int cmp(const void* pa, const void* pb);
int cmp(const void* pa, const void* pb) {
    return *(int*)pa - *(int*)pb;
}
int* maxSubsequence(int* nums, int numsSize, int k, int* returnSize) {
    int* r = (int*)malloc(k * sizeof(int));
    qsort(nums, numsSize, sizeof(int), cmp);
    for (int i = numsSize - k, j = 0; i < numsSize && j < k; i++, j++) {
        r[j] = nums[i];
    }
    return r;
}
int* targetIndices(int* nums, int numsSize, int target, int* returnSize) {
    qsort(nums, numsSize, sizeof(int), cmp);
    int* a = (int*)malloc(sizeof(int) * numsSize);
    int j = 0;
    for (int i = 0; i < numsSize; i++) {
        if (nums[i] == target) {
            a[j] = i;
            j++;
        }
    }
    if (j != 0)
    {
        int* b = (int*)malloc(j * sizeof(int));
        for (int i = 0; i < j; i++) {
            b[i] = a[i];
        }
        qsort(b, j, sizeof(int), cmp);
        return b;
    }
    return a;
}
int main() {
    int a[] = { 2,1,3,3 };
    int k = sizeof(a) / sizeof(int);
    int b[] = { 1,2,5,2,3 };

    int* c = maxSubsequence(a, k, 2, b);
    int* d = targetIndices(b, 5, 2, a);
    for (int i = 0; i < 2; i++) {
        printf("%d ", c[i]);
    }
    for (int i = 0; i < 2; i++) {
        printf("%d ", d[i]);
    }
}